package com.adminsystem.controller;

import com.adminsystem.common.utils.JWTUtil;
import com.adminsystem.common.utils.StringUtils;
import com.adminsystem.service.SysUserService;
import com.system.core.http.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequestMapping("/hello")
@ApiIgnore("临时测试类")
public class testController {
    @Autowired
    private SysUserService sysUserService;
    @GetMapping("/")
    public R index() {
        return R.success();
    }
    @GetMapping("/user/list")
//    @PreAuthorize("hasRole('ROLE_admin')")
    @PreAuthorize("hasAnyAuthority('system_user_list')")
    public R userList(@RequestHeader(required = false) String token) {
        if (StringUtils.isNotEmpty(token)) {
            return R.success(sysUserService.list());
        } else {
            return R.error(401, "没有权限访问");
        }
    }

    @GetMapping("/login")
    public R login() {
        String token = JWTUtil.getJWTToken("mzy");
        return R.success("操作成功",token);
    }
}
